﻿using Microsoft.VisualStudio;
using Microsoft.VisualStudio.Shell;
using Microsoft.VisualStudio.Shell.Interop;
using Sasa.QualityTools.CodeAnalysis.Core.Views;
using Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Properties;
using Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.ViewModels;
using System;
using System.Runtime.InteropServices;

namespace Sasa.QualityTools.CodeAnalysis.FxCopIntegrator.Views
{
    [Guid("1F5973B3-9A67-4BD8-8E8A-8363875538F7")]
    public class CodeAnalysisResultWindowPane : ToolWindowPane, ICodeAnalysisResultView
    {
        public object DataContext
        {
            get
            {
                return ((CodeAnalysisResultContent)Content).DataContext;
            }
            set
            {
                ((CodeAnalysisResultContent)Content).DataContext = value;
            }
        }


        public CodeAnalysisResultWindowPane()
        {
            Caption = Resources.CodeAnalysisResultWindowTitle;
            BitmapResourceID = 301;
            BitmapIndex = 0;

            var content = new CodeAnalysisResultContent();
            content.DataContext = new CodeAnalysisResultViewModel();
            Content = content;
        }


        public void Show()
        {
            var frame = (IVsWindowFrame)Frame;
            ErrorHandler.ThrowOnFailure(frame.Show());
        }

        public void Close()
        {
            var frame = (IVsWindowFrame)Frame;
            ErrorHandler.ThrowOnFailure(frame.Hide());
        }

        protected override void OnCreate()
        {
            var content = (CodeAnalysisResultContent)Content;
            content.LoadSetting();
            base.OnCreate();
        }

        protected override void OnClose()
        {
            var content = (CodeAnalysisResultContent)Content;
            content.SaveSetting();
            base.OnClose();
        }
    }
}